package com.example.bootdemo.controller;

import com.example.bootdemo.bean.Student;
import com.example.bootdemo.tool.ClassifyStudents;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.lang.reflect.Array;
import java.util.*;

import static com.example.bootdemo.BootdemoApplication.*;

@Controller
@RestController
@CrossOrigin()
public class StudentController {


    @ResponseBody
    @PostMapping("ViewTable")
    //public List<Student> ViewTable(@RequestBody String student){
    public String ViewTable(@RequestBody List<Student> intStudent){
//        System.out.println("kkkkkkkk");
//        System.out.println(intStudent.toString());

        students=intStudent;
        map= ClassifyStudents.Classify(intStudent, map);
        schools = ClassifyStudents.schoolsList(map);
//       for(Student student1:intStudent){
//           System.out.println(student1.getStudentNumb());
//           System.out.println(student1.getStudentName());
//           System.out.println(student1.getStudentSex());
//       }
            return "";
    }
    @ResponseBody
    @PostMapping("outputExcel")
    //public List<Student> ViewTable(@RequestBody String student){
    public List<Student> outputExcel(){
//        System.out.println("kkkkkkkk");
//        System.out.println(intStudent.toString());
        List<Student> students=ClassifyStudents.selectedStudentMapToList(selectedStudent);
//        for (Student student:students){
//            System.out.println("ID:"+student.getStudentNumb()+"   "+"name:"+student.getStudentName()+"   "+"choiceSchool:"+student.getChoiceSchool());
//        }
        return students;
    }
    @ResponseBody
    @PostMapping("clean")
    public void clean(){
        students.clear();
        //public static List<List<Student>> result = new ArrayList<>();
        //一个静态的用于存储分类好的学生信息map
        map.clear();
        //一个静态的用于存储学校信息的List
        schools.clear();
        //一个静态的用于存储抽出的学生信息的Map
        selectedStudent.clear();
        System.out.println(students.size());
        System.out.println(map.size());
        System.out.println(schools.size());
        System.out.println(selectedStudent.size());
    }
//    @RequestMapping("view")
//    public String myTestController5(@RequestBody Student student, @RequestParam("arrays") List<String> arrays) {
//        System.out.println(student.toString());
//        StringBuffer sb = new StringBuffer();
//        for (String array : arrays) {
//            sb.append(array);
//            sb.append("  ");
//            System.out.println(array);
//        }
//        return sb.toString() + student.toString();
//    }

}
